<html>
<head><meta charset="utf-8"><title>Bounds on const params? · project-const-generics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/index.html">project-const-generics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html">Bounds on const params?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="242884030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242884030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242884030">(Jun 16 2021 at 13:57)</a>:</h4>
<p>Is this already being designed? I'm very interested in being able to express that my function accepts a [T; N] where N &lt; 8, let's say</p>



<a name="242884156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242884156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242884156">(Jun 16 2021 at 13:58)</a>:</h4>
<p>(ideally the 8 itself would be calculated based on associated consts, but that will at least also need lazy normalization IIUC)</p>



<a name="242884212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242884212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242884212">(Jun 16 2021 at 13:59)</a>:</h4>
<p>I think what you're looking for is <code>feature(const_evaluatable_checked)</code></p>



<a name="242884351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242884351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242884351">(Jun 16 2021 at 13:59)</a>:</h4>
<p>I was just looking at that, but it seems to be about other things; like, in <a href="https://hackmd.io/OZG_XiLFRs2Xmw5s39jRzA?view">https://hackmd.io/OZG_XiLFRs2Xmw5s39jRzA?view</a> it talks about arithmetic expressions like N + 1</p>



<a name="242884431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242884431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242884431">(Jun 16 2021 at 14:00)</a>:</h4>
<p>y</p>



<a name="242884446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242884446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242884446">(Jun 16 2021 at 14:00)</a>:</h4>
<p>so you could write like</p>



<a name="242884460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242884460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242884460">(Jun 16 2021 at 14:00)</a>:</h4>
<p>I would expect placing bounds on a const generic value is simpler than evaluating a compound expression</p>



<a name="242884528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242884528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242884528">(Jun 16 2021 at 14:00)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="p">,</span><span class="w"> </span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">arg</span>: <span class="p">[</span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">])</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="p">[();</span><span class="w"> </span><span class="mi">7</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">N</span><span class="p">]</span>: <span class="p">{</span><span class="w"></span>

<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="242884584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242884584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242884584">(Jun 16 2021 at 14:01)</a>:</h4>
<p>and then if you call it with <code>N &gt;= 8</code> it would give you a compile error because <code>7 - N</code> doesnt evaluate successfully xd</p>



<a name="242884616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242884616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242884616">(Jun 16 2021 at 14:01)</a>:</h4>
<p>ah, ok</p>



<a name="242884648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242884648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242884648">(Jun 16 2021 at 14:01)</a>:</h4>
<p>the way that const evaluatable checked works is basically where clauses that make the caller prove that some expression can be evalauted</p>



<a name="242884673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242884673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242884673">(Jun 16 2021 at 14:02)</a>:</h4>
<p>currently the feature is pretty WIP though <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="242884782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242884782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242884782">(Jun 16 2021 at 14:02)</a>:</h4>
<p>for example the only way to add these where clauses is to just use the expression you want to be evaluatable, somewhere in the fn signature</p>



<a name="242884798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242884798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242884798">(Jun 16 2021 at 14:02)</a>:</h4>
<p>and then implied bounds go brrr...</p>



<a name="242885103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242885103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242885103">(Jun 16 2021 at 14:04)</a>:</h4>
<p>mkay</p>



<a name="242885163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242885163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242885163">(Jun 16 2021 at 14:04)</a>:</h4>
<p>just as UX, <code>7 - N</code> seems a fair bit harder to understand than <code>N &lt; 8</code></p>



<a name="242885195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242885195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242885195">(Jun 16 2021 at 14:04)</a>:</h4>
<p>yea for sure</p>



<a name="242885282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242885282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242885282">(Jun 16 2021 at 14:05)</a>:</h4>
<p>shiny future <span aria-label="sparkles" class="emoji emoji-2728" role="img" title="sparkles">:sparkles:</span> would be writing something like<br>
<code>fn foo&lt;const N: usize, T&gt;(arg: [T; N]) where { N &lt; 8 }</code> or something</p>



<a name="242885303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242885303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242885303">(Jun 16 2021 at 14:05)</a>:</h4>
<p>not quite there yet though</p>



<a name="242885312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242885312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242885312">(Jun 16 2021 at 14:05)</a>:</h4>
<p>yeah, that would be cool</p>



<a name="242885342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242885342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242885342">(Jun 16 2021 at 14:05)</a>:</h4>
<p>(congrats on your new role as compiler contributor BTW!)</p>



<a name="242885374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242885374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242885374">(Jun 16 2021 at 14:06)</a>:</h4>
<p>aa thanks :)</p>



<a name="242885425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/Bounds%20on%20const%20params%3F/near/242885425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/Bounds.20on.20const.20params.3F.html#242885425">(Jun 16 2021 at 14:06)</a>:</h4>
<p>it was a surprise for sure haha</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>